{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![logo](images/opendata-top-transblack.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Get Running the 8 TeV Example in Python\n",
    "\n",
    "\n",
    "\n",
    "You can follow the steps to run 8 TeV example and see the results."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "## 1. Preparation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.1 Import necessery modules that provide a way of using operating system dependent functionality. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import os"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Print current system time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fre Jul 26 20:40:28 CEST 2019\n",
      "\n"
     ]
    }
   ],
   "source": [
    "myCmd = os.popen('date').read()\n",
    "print(myCmd)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.2 Create a new folder \"python-8tev\" in which you place your data and code"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Create a directory"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "command1 = 'mkdir python-8tev'\n",
    "os.system(command1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- List the files in your directory"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "total 112K\n",
      "-rw-r--r-- 1 summerstudent users  125 Jul 26 20:39 README.md\n",
      "drwxr-xr-x 2 summerstudent users 4.0K Jul 26 20:39 images\n",
      "-rw-r--r-- 1 summerstudent users  14K Jul 26 20:39 get-running-8-tev-code-python.ipynb\n",
      "-rw-r--r-- 1 summerstudent users 9.6K Jul 26 20:39 get-running-8-tev-code-cpp.ipynb\n",
      "-rw-r--r-- 1 summerstudent users 8.0K Jul 26 20:39 get-running-13-tev-python-code.ipynb\n",
      "-rw-r--r-- 1 summerstudent users  64K Jul 26 20:39 get-running-13-tev-cpp-code.ipynb\n",
      "drwxr-xr-x 2 summerstudent users 4.0K Jul 26 20:40 python-8tev\n",
      "\n"
     ]
    }
   ],
   "source": [
    "myCmd = os.popen('ls -lhrt').read()\n",
    "print(myCmd)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Print your current path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/student/notebooks/demos-framework-software-notebooks\n",
      "\n"
     ]
    }
   ],
   "source": [
    "myCmd = os.popen('pwd').read()\n",
    "print(myCmd)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.3 Prepare the code "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Change current directory to \"python-8tev\" "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "os.chdir(\"python-8tev/\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Print your current path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/student/notebooks/demos-framework-software-notebooks/python-8tev\n",
      "\n"
     ]
    }
   ],
   "source": [
    "myCmd = os.popen('pwd').read()\n",
    "print(myCmd)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Print current system time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fre Jul 26 20:40:28 CEST 2019\n",
      "\n"
     ]
    }
   ],
   "source": [
    "myCmd = os.popen('date').read()\n",
    "print(myCmd)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Clone the code of 8TeV from github"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "command2 = 'git clone https://github.com/atlas-outreach-data-tools/atlas-outreach-data-tools-framework.git'\n",
    "os.system(command2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.4 Prepare the 8 TeV dataset"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Change current directory to \"Input\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "os.chdir(\"atlas-outreach-data-tools-framework/Input/\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Print your current path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/student/notebooks/demos-framework-software-notebooks/python-8tev/atlas-outreach-data-tools-framework/Input\n",
      "\n"
     ]
    }
   ],
   "source": [
    "myCmd = os.popen('pwd').read()\n",
    "print(myCmd)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fre Jul 26 20:40:29 CEST 2019\n",
      "\n"
     ]
    }
   ],
   "source": [
    "myCmd = os.popen('date').read()\n",
    "print(myCmd)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Download dataset\n",
    "\n",
    "**Note**: Download this dataset only once. If you have run it before, please go to  **2. Run Analysis** part directly."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Print current system time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "command31 = 'wget -c http://opendata.atlas.cern/release/samples/Data.zip'\n",
    "os.system(command31)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Print current system time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fre Jul 26 20:41:15 CEST 2019\n",
      "\n"
     ]
    }
   ],
   "source": [
    "myCmd = os.popen('date').read()\n",
    "print(myCmd)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Unzip the dataset you download"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "command4 = 'unzip Data.zip'\n",
    "os.system(command4)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Remove the zip file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "command5 = 'rm -rf Data.zip'\n",
    "os.system(command5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Print current system time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fre Jul 26 20:41:35 CEST 2019\n",
      "\n"
     ]
    }
   ],
   "source": [
    "myCmd = os.popen('date').read()\n",
    "print(myCmd)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Download dataset\n",
    "\n",
    "**Note**: Download this dataset only once. If you have run it before, please go to  **2. Run Analysis** part directly."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "command32 = 'wget -c http://opendata.atlas.cern/release/samples/MC.zip'\n",
    "os.system(command32)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Unzip the dataset you download"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "command4 = 'unzip MC.zip'\n",
    "os.system(command4)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Remove the zip file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "command5 = 'rm -rf MC.zip'\n",
    "os.system(command5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Print current system time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fre Jul 26 20:47:59 CEST 2019\n",
      "\n"
     ]
    }
   ],
   "source": [
    "myCmd = os.popen('date').read()\n",
    "print(myCmd)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Change current path to parent directory"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "os.chdir(\"..\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Print your current path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/student/notebooks/demos-framework-software-notebooks/python-8tev/atlas-outreach-data-tools-framework\n",
      "\n"
     ]
    }
   ],
   "source": [
    "myCmd = os.popen('pwd').read()\n",
    "print(myCmd)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Print current system time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fre Jul 26 20:47:59 CEST 2019\n",
      "\n"
     ]
    }
   ],
   "source": [
    "myCmd = os.popen('date').read()\n",
    "print(myCmd)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. Run the TTbarAnalysis"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Run \"python RunScript.py\" with option \"-a TTbarAnalysis\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "command6 = 'python2 RunScript.py -a TTbarAnalysis'\n",
    "os.system(command6)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Print current system time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fre Jul 26 21:14:10 CEST 2019\n",
      "\n"
     ]
    }
   ],
   "source": [
    "myCmd = os.popen('date').read()\n",
    "print(myCmd)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. Plot Results"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Run \"PlotResults.py\" and \"Configurations/PlotConf_TTbarAnalysis.py\" to plot the results."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# plot results\n",
    "command7 = 'python2 PlotResults.py Configurations/PlotConf_TTbarAnalysis.py' \n",
    "os.system(command7)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Print current system time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fre Jul 26 21:14:14 CEST 2019\n",
      "\n"
     ]
    }
   ],
   "source": [
    "myCmd = os.popen('date').read()\n",
    "print(myCmd)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- List all the plots in \"Output\" folder"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "command8 = 'ls -lhrt Output/'\n",
    "os.system(command8)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Print your current path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/student/notebooks/demos-framework-software-notebooks/python-8tev/atlas-outreach-data-tools-framework\n",
      "\n"
     ]
    }
   ],
   "source": [
    "myCmd = os.popen('pwd').read()\n",
    "print(myCmd)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![etmiss](python-8tev/atlas-outreach-data-tools-framework/Output/etmiss.png)\n",
    "![](python-8tev/atlas-outreach-data-tools-framework/Output/jet_eta.png)  \n",
    "![](python-8tev/atlas-outreach-data-tools-framework/Output/jet_jvf.png)\n",
    "![](python-8tev/atlas-outreach-data-tools-framework/Output/jet_m.png)                                                              \n",
    "![](python-8tev/atlas-outreach-data-tools-framework/Output/jet_MV1.png)\n",
    "![](python-8tev/atlas-outreach-data-tools-framework/Output/jet_pt.png)\n",
    "![](python-8tev/atlas-outreach-data-tools-framework/Output/lep_charge.png)\n",
    "![](python-8tev/atlas-outreach-data-tools-framework/Output/lep_d0.png)\n",
    "![](python-8tev/atlas-outreach-data-tools-framework/Output/lep_E.png)              \n",
    "![](python-8tev/atlas-outreach-data-tools-framework/Output/lep_eta.png)\n",
    "![](python-8tev/atlas-outreach-data-tools-framework/Output/lep_n.png)\n",
    "![](python-8tev/atlas-outreach-data-tools-framework/Output/lep_phi.png)\n",
    "![](python-8tev/atlas-outreach-data-tools-framework/Output/lep_pt.png)\n",
    "![](python-8tev/atlas-outreach-data-tools-framework/Output/n_jets.png)\n",
    "![](python-8tev/atlas-outreach-data-tools-framework/Output/WtMass.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Done!"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Raw Cell Format",
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
